package com.study.cloud.custom.registerinterface;

import com.study.cloud.custom.registerclass.HelloService;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.GenericBeanDefinition;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.type.AnnotationMetadata;

public class HelloInterfaceRegister implements ImportBeanDefinitionRegistrar {

    @Override
    public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {


        MyFactoryBean myFactoryBean = new MyFactoryBean();
        BeanDefinitionBuilder beanDefinitionBuilder =
                BeanDefinitionBuilder.genericBeanDefinition(IHelloService.class,()->myFactoryBean.getObject());

        AbstractBeanDefinition beanDefinition = beanDefinitionBuilder.getBeanDefinition();


        registry.registerBeanDefinition("helloService",beanDefinition);



    }

}
